package com.zeta.eduservice.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.zeta.eduservice.entity.excel.QuestionExcel;
import com.zeta.eduservice.entity.question.ChapterAQuestionTypeSysAndQuestion;
import com.zeta.eduservice.entity.question.EduQuestion;
import com.zeta.eduservice.entity.vo.QuestionUploadVo;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndChoicequestionService;
import com.zeta.eduservice.service.ChapterAQuestionTypeSysAndQuestionService;
import com.zeta.eduservice.service.EduQuestionService;

public class UploadQuestionExcelListener extends AnalysisEventListener<QuestionExcel>{

	EduQuestionService service;
	ChapterAQuestionTypeSysAndQuestionService chapterAQuestionTypeSysAndquestionServiceString;
	QuestionUploadVo chapterId;
	public UploadQuestionExcelListener() {}
	public UploadQuestionExcelListener( EduQuestionService questionService,ChapterAQuestionTypeSysAndQuestionService chapterAQuestionTypeSysAndquestionServiceString ,QuestionUploadVo chapterId) {
		// TODO Auto-generated constructor stub
		this.service=questionService;
		this.chapterAQuestionTypeSysAndquestionServiceString=chapterAQuestionTypeSysAndquestionServiceString;
		this.chapterId=chapterId;
	}
	@Override
	public void invoke(QuestionExcel data, AnalysisContext context) {
		// TODO Auto-generated method stub
		EduQuestion eduQuestion = new EduQuestion();
		eduQuestion.setContent(data.getContent());
		eduQuestion.setAnswer(data.getAnswer());
		eduQuestion.setDifficulty(data.getDifficluty());
		eduQuestion.setTitle(data.getTitle());
//		eduQuestion.setChapterId(chapterId);
		eduQuestion.setType(chapterId.getSysTypeId());
		service.save(eduQuestion);
		ChapterAQuestionTypeSysAndQuestion chapterAQuestionTypeSysAndQuestion = new ChapterAQuestionTypeSysAndQuestion();
		chapterAQuestionTypeSysAndQuestion.setQuestionId(eduQuestion.getId()).setRegistId(chapterId.getTypeId());
		chapterAQuestionTypeSysAndquestionServiceString.save(chapterAQuestionTypeSysAndQuestion);
	}

	@Override
	public void doAfterAllAnalysed(AnalysisContext context) {
		// TODO Auto-generated method stub
		
	}

}
